from wxpita import *

f = SizedFrame(size=(400, 500)) [
    TreeCtrl(name='tree',
             style='tr_has_buttons|tr_hide_root|tr_lines_at_root',
             expand=True, proportion=1)
]

@f.Init
def _():
    tree = f.tree
    
    size = (16,16)
    imageLst = wx.ImageList(16, 16)

    for artId in (wx.ART_FOLDER, wx.ART_FOLDER_OPEN, wx.ART_NORMAL_FILE):
        imageLst.Add(
            wx.ArtProvider_GetBitmap(artId, wx.ART_OTHER, size))
    
    folderId, folderOpenId, fileId = 0, 1, 2

    # SetImageList doesn't work well because the ImageList is garbage-
    # collected as soon as this method returns. But if you use
    # AssignImageList, the TreeCtrl keeps a reference of the ImageList.
    #tree.SetImageList(imageLst)    
    tree.AssignImageList(imageLst)
    
    root = tree.AddRoot('Root Item')
    tree.SetItemImage(root, folderId, wx.TreeItemIcon_Normal)
    tree.SetItemImage(root, folderOpenId, wx.TreeItemIcon_Expanded)
    
    for i in range(15):
        child = tree.AppendItem(root, 'Item %d' % i)
        tree.SetItemImage(child, folderId, wx.TreeItemIcon_Normal)
        tree.SetItemImage(child, folderOpenId, wx.TreeItemIcon_Expanded)
        
        for j in range(4):
            child2 = tree.AppendItem(child, 'Item %d.%d' % (i,j))
            tree.SetItemImage(child2, fileId, wx.TreeItemIcon_Normal)

        if i % 4 == 0:
            tree.Expand(child)

##        tree.Expand(root)

f.Show('TreeCtrl with Images Example')
